package org.small.shop.phone.api.utils;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ReadProperties {

	private static Logger logger = LoggerFactory.getLogger(ReadProperties.class);

	private Properties errorMessage;

	private Properties config;

	private Properties application;

	private static ReadProperties instance;

	public static synchronized ReadProperties getInstance() {

		if (instance == null)
			instance = new ReadProperties();

		return instance;
	}

	public synchronized Properties getErrorMessageProperties() {
		if (errorMessage == null) {
			InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("errorMessage.properties");
			errorMessage = new Properties();
			try {
				errorMessage.load(inputStream);
			} catch (IOException e) {
				logger.info("ErrorMessagePropertiese is null :" + e.getMessage());
			}
		}
		return errorMessage;
	}

	public synchronized Properties getConfigProperties() {
		if (config == null) {
			InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("config.properties");
			config = new Properties();
			try {
				config.load(inputStream);
			} catch (IOException e) {
				logger.info("config is null :" + e.getMessage());
			}
		}
		return config;
	}

	public synchronized Properties getApplicationProperties() {

		if (application == null) {
			InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("application.properties");
			application = new Properties();
			try {
				application.load(inputStream);
			} catch (IOException e) {
				logger.info("application is null :" + e.getMessage());
			}
		}

		return application;
	}
}
